package stu.day9_day18;

public class LeetCode304 {

    int[][] array;


    public LeetCode304(int[][] matrix) {
        int len = matrix.length;
        int heg = matrix[0].length;
        array = new int[len+1][heg+1];

        for(int i=1;i<len+1;i++){
            for (int j=1;j<heg+1;j++){
                array[i][j]=array[i-1][j]+array[i][j-1]-array[i-1][j-1]+matrix[i-1][j-1];
            }
        }
    }

    public int sumRegion(int row1, int col1, int row2, int col2) {
        return array[row2+1][col2+1]-array[row1][col1+1]-array[row1+1][col1]+array[row1][col1];
    }
}
